#!/usr/bin/python
# coding=utf8

from database import Storage
import cgi
import json

storage = Storage()
form = cgi.FieldStorage()

print "Content-Type: application/json\n"

if ("limit" in form) and ("start" in form):
    res = storage.get_main(int(form["qid"].value), long(form["start"].value), 
                           int(form["limit"].value))
else:
    res = storage.get_main(int(form["qid"].value))
print json.dumps(res)